package com.weiwei.diancan.utils;

import com.weiwei.diancan.bean.LoginBean;
import com.weiwei.diancan.bean.OrderWapper;
import com.weiwei.diancan.cache.CacheConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by BMW on 2017/1/13.
 */
public class OrderUtils {
    /**
     *
     * @param orderId
     * @param type  0,获取全部订单   1，获取对应订单id的订单
     * @return
     */
    public static List<OrderWapper> getOederList(String orderId,int type){
        List<OrderWapper> list = new ArrayList<>();  //全部订单列表
        List<OrderWapper> detailOrder = new ArrayList<>(); //对应订单Id的列表
        List<OrderWapper> detailOrdertype = new ArrayList<>(); //对应订单Id的列表

        LoginBean login = CacheConfig.getInst().getLogin();
        List<LoginBean.TypeListBean> type_list = login.getType_list();
        for(LoginBean.TypeListBean typeListBean:type_list){
            List<LoginBean.TypeListBean.TabListBean> tab_list = typeListBean.getTab_list();
            String type_id = typeListBean.getType_id();
            for(LoginBean.TypeListBean.TabListBean tabListBean:tab_list){
                String tab_name = tabListBean.getTab_name();
                String tab_id = tabListBean.getTab_id();
                String tab_max_person = tabListBean.getTab_person();
                List<LoginBean.OrderListBean> order_list = tabListBean.getOrder_list();
                if(order_list!=null){
                    for(LoginBean.OrderListBean orderListBean:order_list){
                        double order_prices = 0;
                        List<LoginBean.OrderListBean.LogListBean> log_list = orderListBean.getLog_list();
                        if(log_list!=null){
                            for(LoginBean.OrderListBean.LogListBean logListBean:log_list){
                                order_prices+=Double.parseDouble(logListBean.getLog_money());
                            }
                        }


                        OrderWapper orderWapper = new OrderWapper();
                        orderWapper.setOrder_no(orderListBean.getOrder_no());
                        orderWapper.setTime(orderListBean.getInsert_time());
                        orderWapper.setTab_name(tab_name);
                        orderWapper.setTab_max_people(tab_max_person);
                        orderWapper.setTab_people(orderListBean.getOrder_person());
                        orderWapper.setOrder_price(order_prices+"");
                        orderWapper.setOrder_state(orderListBean.getOrder_state());
                        orderWapper.setTab_id(tab_id);
                        orderWapper.setType_id(type_id);
                        list.add(orderWapper);

                        if(orderId!=null){
                            if(orderId.equals(orderListBean.getOrder_id())
                                    ||orderId.equals(orderListBean.getFather_id())){
                                detailOrder.add(orderWapper);
                            }
                        }

                        if(type == 1) {
                            if (orderId != null) {
                                if (orderId.equals(orderListBean.getOrder_id())) {
                                    detailOrdertype.add(orderWapper);
                                    return detailOrdertype;
                                }
                            }
                        }
                    }
                }
            }
        }

        if(orderId!=null)
            return detailOrder;
        return list;
    }
}
